<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>还款申请</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div id="pageInTab" class="pageInTab">
			<form id="fnc_prj_pay_sch_form">
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">项目基础信息</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">项目名称</div>
						<div class="field">
							<span name="FNCPRJNM" id="FNCPRJNM" >${bscinfo.FNCPRJNM}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">项目编号</div>
						<div class="field">
							<span name="FNCPRJID" id="FNCPRJID" >${bscinfo.FNCPRJID}</span>
							<input type="hidden" id="payschid" name="payschid" value="${payschid}">
							<input type="hidden" id="total0" name="total0" value="${total0}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">创建日期</div>
						<div class="field">
							<span name="CRTTM" id="CRTTM" >${bscinfo.CRTTM}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">融资机构</div>
						<div class="field">
							<span name="FUNDRASINSNM" id="FUNDRASINSNM" >${bscinfo.FUNDRASINSNM}</span>
							<input type="hidden" id="fundrasinsid" name="fundrasinsid" value="${bscinfo.FUNDRASINSID}">
							<input type="hidden" id="repaystcd" name="repaystcd" value="${repaystcd}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">融资方案</div>
						<div class="field">
							<span name="FNCSCMNM" id="FNCSCMNM" >${bscinfo.FNCSCMNM}</span>
							<input type="hidden" id="fncscmid" name="fncscmid" value="${bscinfo.FNCSCMID}">
							<input type="hidden" id="repytp" name="repytp" value="${bscinfo.REPY_TP}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">项目金额</div>
						<div class="field">
							<span name="FNCPRJAMT" id="FNCPRJAMT" >${bscinfo.FNCPRJAMT}</span>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">实际融资金额</div>
						<div class="field">
							<span name="FNCFIAMT" id="FNCFIAMT" >${bscinfo.ACFIAMT}</span>
							<input type="hidden" id="famt" name="famt" value="${bscinfo.ACFIAMT}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">支付表数量</div>
						<div class="field">
							<span name="PAYCNT" id="PAYCNT" >${bscinfo.PAYCNT}</span>
						</div>
					</div>
				</div>
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">账户信息</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">机构收款账户</div>
						<div class="field">
							<input name="recvAcc" id="recvAcc" type="text" class="ui-textbox" value=""  validate="{required:true}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">我司付款账户</div>
						<div class="field">
							<input name="payAcc" id="payAcc" style="display:none" type="text" value="${bscinfo.PACCID}">
							<input  name="payAccNo" id="payAccNo"  value="${paccno}"  onclick="queryMy()">
							<input name="payAccNm" id="payAccNm"  type="hidden" value="${bkAccInfoVO.accNm}">
						</div>
					</div>
				</div>	
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">融资端费用</span>
					</div>
					<div class="fieldBox col_100">
							<div id="cost0" class="sq-grid">
							</div>
					</div>
				</div>
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">还款明细</span>
					</div>
					<div class="fieldBox col_100">
							<div id="cost1" class="sq-grid">
							</div>
					</div>
				</div>
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="fieldBox col_100">
						<div class="label">还款本金合计</div>
						<div class="field">
							<input name="sumFeeAmt" id="sumFeeAmt" type="text" class="ui-textbox" disabled="disabled">
						</div>
					</div>
				</div>
			</form>
		</div>

		<div class="btnsBox" id="ss" align="center">
			<span id="repay_list_add_btn_id" class="sq-button sq-button-round" >发起付款流程</span>
		</div>

<!-- 		<div class="btnsBox" id="ss">
			<span id="repay_list_rtn_btn_id" class="sq-button sq-button-round" >返回</span>
		</div> -->
	</div>
<!-- 嵌入账户详情 -->
<jsp:include page="../mrgnmanageinfo/showAcc.jsp"></jsp:include>
	<script type="text/javascript">
	var griddata0,griddata1;
	$(function () {
		if($("#repaystcd").val()==2){
			alert("当前明细正处于还款阶段,不能发起修改!");
        	$("#ss").hide();
		}
		initRecvList();
		//initPayList();
		initCost0Grid();
		initDetlGrid();
    	$("#fnc_prj_pay_sch_form").ligerForm({
    		validate:true
        });
		saveFncPrjPayEvent();
	});
	
    function initCost0Grid()
    {
    	var schid = $("#payschid").val();
    	griddata0 = $("#cost0").ligerGrid({
	    	url: '<%=path%>/rfbase/fncprjpaysch/initCost0Grid.do?payschid='+schid,
	    	method : 'get',
            columns: [
            { display: '费用名称', name: 'COST_NM', width: 160, type: 'text'},
            { display: '还款日', width: 150, name: 'PAY_DT',render:renderDate},
            { display: '应还金额', name: 'FEE_AMT', width: 160, type: 'float'},
            { display: '已还金额', name: 'PAID_UP_AMT', width: 160, type: 'float'},
            { display: '剩余金额', name: 'AR_AMT', width: 160, type: 'float',
                totalSummary:
                {
                    render: function (suminf, column, cell)
                    {
                        return '<div>合计:' + suminf.sum + '</div>';
                    },
                    align: 'left'
                }
			},
            { display: '应还金额浮动', name: 'FLOAT_AMT',type: 'float', 
                editor: { type: 'float' }, align: 'left', width: 160
            },
            { display: '本次还款额', name: 'ACTUAL_AMT',type: 'float', 
                editor: { type: 'float' }, align: 'left', width: 160,
                totalSummary:
                {
                    render: function (suminf, column, cell)
                    {
                        return '<div>' + suminf.sum + '</div>';
                    },
                    align: 'left'
                }
            },
            { display: '备注', name: 'FEE_REM', width: 200, type: 'text',
                editor: { type: 'text' }, align: 'left'
            },
            { display: '实际付款时间', name: 'ACT_PYMT_DT', width: 160, type: 'text',render:renderDate},
            { display: '实际付款金额', name: 'ACT_PYMT_AMT', width: 160, type: 'text'},
            { display: '机构收款账号', name: 'rcvpymtAccNoHtml', width: 150, type: 'text'
            },
           /*  { display: '机构收款账号', name: 'rcvpymtAccNo', width: 150, type: 'text',
            	render:function (rowdata, rowindex, value, column) { 
            		var h="";
	            	if(rowdata.rcvpymtAccId!=null){
            			 h ="<a href='#' onclick='showInsAcc("+rowdata.rcvpymtAccId+")'> <font color='blue'>"+rowdata.rcvpymtAccNo+"</font></a>";
	            	}
	            	return h;
        		}
            },  */
            { display: '我司付款账户', name: 'payAccNoHtml', width: 200, type: 'text'},
            
          /*   { display: '我司付款账号', name: 'payAccNo', width: 200, type: 'text',
            	render:function (rowdata, rowindex, value, column) { 
	            	var h="";
	            	if(rowdata.payAccId!=null){
            		 h ="<a href='#' onclick='showSysAcc("+rowdata.payAccId+")'> <font color='blue'>"+rowdata.payAccNo+"</font></a>";
	            	}
	            	return h;
            	}
            }, */
            { display: '逻辑序号', name: 'ID',width:0, align:'left', hide:true}
            ],
            enabledEdit: true, isScroll: true,rownumbers:true,
            onBeforeEdit: f_onBeforeEdit0,
            onBeforeCheckRow: function (checked, data, rowindex, rowobj)
            {
                if (data.AR_AMT == 0){
                	alert('本期还款已结清，无需勾选还款!');
                    return false;
                }
                return true;
            },
            onBeforeSubmitEdit: f_onBeforeSubmitEdit0,
            onSelectRow : function (rowdata, rowid, rowobj)
            {
                var manager = $("#cost0").ligerGetGridManager();
                var aramt = accAdd(rowdata.FEE_AMT-rowdata.PAID_UP_AMT,rowdata.FLOAT_AMT);
                if (aramt == 0){
            		manager.unselect(rowid);
                }
				if(aramt != 0 && (rowdata.ACTUAL_AMT == 0 || rowdata.ACTUAL_AMT == null)){
	      			manager.updateRow(rowdata,{
	      				ACTUAL_AMT: aramt
	    	        });
                }
            },
            onUnSelectRow  : function (rowdata, rowid, rowobj)
            {
                var manager = $("#cost0").ligerGetGridManager();
    	        manager.updateRow(rowdata,{
    	        	ACTUAL_AMT: 0,
    	        	FLOAT_AMT: 0,
    	        	FEE_REM: ''
    	        });
            },
            onAfterShowData: f_onAfterShowData0,
            width: '100%',height:200,checkbox:true,usePager:false
        });
    }
	
    function initDetlGrid()
    {
    	var schid = $("#payschid").val();
    	griddata1 = $("#cost1").ligerGrid({
	    	url: '<%=path%>/rfbase/fncprjpaysch/initDetlGrid.do?payschid='+schid,
	    	method : 'get',
            columns: [
            { display: '期数', name: 'payPd', width: 50, type: 'int' },
            { display: '应还款项', name: 'feeClsCd',width: 150, type: 'text',
                render: function (item)
                {
                    if (parseInt(item.feeClsCd) == 1) return '本金';
                    if (parseInt(item.feeClsCd) == 2) return '利息';
                    if (parseInt(item.feeClsCd) == 3) return '超额抵押';
                    return '其他费用';
                }},
            { display: '还款日', width: 150, name: 'payDt',render:renderDate},
            { display: '应还金额', name: 'feeAmt', width: 160, type: 'float'},
            { display: '已还金额', name: 'paidUpAmt', width: 160, type: 'float'},
            { display: '剩余金额', name: 'arAmt', width: 160, type: 'float',
                totalSummary:
                {
                    render: function (suminf, column, cell)
                    {
                        return '<div>合计:' + suminf.sum + '</div>';
                    },
                    align: 'left'
                }
			},
            { display: '应还金额浮动', name: 'floatAmt',type: 'float', 
                editor: { type: 'float' }, align: 'left', width: 160,
            },
            { display: '本次还款额', name: 'actualAmt',type: 'float', 
                editor: { type: 'float' }, align: 'left', width: 160,
                totalSummary:
                {
                    render: function (suminf, column, cell)
                    {
                        return '<div>' + suminf.sum + '</div>';
                    },
                    align: 'left'
                }
            },
            { display: '备注', name: 'feeRem', width: 200, type: 'text',
                editor: { type: 'text' }, align: 'left'
            },
            { display: '实际付款时间', name: 'actPymtDt',render:renderDate},
            { display: '实际付款金额', name: 'actPymtAmt', width: 160, type: 'text'},
            { display: '机构收款账号', name: 'rcvpymtAccNoHtml', width: 150, type: 'text'
            }, 
           /*  { display: '机构收款账号', name: 'rcvpymtAccNo', width: 150, type: 'text',
            	render:function (rowdata, rowindex, value, column) { 
            		var h="";
	            	if(rowdata.rcvpymtAccId!=null){
            			 h ="<a href='#' onclick='showInsAcc("+rowdata.rcvpymtAccId+")'> <font color='blue'>"+rowdata.rcvpymtAccNo+"</font></a>";
	            	}
	            	return h;
        		}
            }, */
            { display: '我司付款账户', name: 'payAccNm', width: 200, type: 'text'},
            { display: '我司付款账号', name: 'payAccNoHtml', width: 200, type: 'text'},
           /*  { display: '我司付款账号', name: 'payAccNo', width: 200, type: 'text',
            	render:function (rowdata, rowindex, value, column) { 
	            	var h="";
	            	if(rowdata.payAccId!=null){
            		 h ="<a href='#' onclick='showSysAcc("+rowdata.payAccId+")'> <font color='blue'>"+rowdata.payAccNo+"</font></a>";
	            	}
	            	return h;
            	}
            }, */
            { display: '逻辑序号', name: 'id',width:0, align:'left', hide:true}
            ],
            enabledEdit: true, isScroll: true,rownumbers:true,
            onBeforeEdit: f_onBeforeEdit,
            onBeforeCheckRow: function (checked, data, rowindex, rowobj)
            {
                if (data.arAmt == 0){
                	alert('本期还款已结清，无需勾选还款!');
                    return false;
                }
                return true;
            },
            onBeforeSubmitEdit: f_onBeforeSubmitEdit,
            onSelectRow : function (rowdata, rowid, rowobj)
            {
                var manager = $("#cost1").ligerGetGridManager();
        		var aramt = accAdd(rowdata.feeAmt-rowdata.paidUpAmt,rowdata.floatAmt) ;
                if (aramt == 0){
            		manager.unselect(rowid);
                }
				if(aramt != 0 && (rowdata.actualAmt == 0 || rowdata.actualAmt == null)){
	      			manager.updateRow(rowdata,{
	    	        	actualAmt: aramt
	    	        });
                }
				
				//设置机构收款账户
				var recvAccId = $("#recvAcc").ligerGetComboBoxManager().getValue();
				var recvAcc = $("#recvAcc").ligerGetComboBoxManager(). getText();
				if(recvAccId != "" && recvAcc != "") {
					var rcvpymtAccNoHtml ="<a href='#' onclick='showInsAcc("+recvAccId+")'> <font color='blue'>"+recvAcc+"</font></a>";
					manager.updateRow(rowdata,{
						rcvpymtAccNoHtml: rcvpymtAccNoHtml
	    	        });
				}
				
				
				//设置我司付款账号
				var payAcc = $("#payAcc").val();
				var payAccNo = $("#payAccNo").val();
				if(payAcc != "" && payAccNo != "") {
					var payAccNoHtml ="<a href='#' onclick='showSysAcc("+payAcc+")'> <font color='blue'>"+payAccNo+"</font></a>";
					manager.updateRow(rowdata,{
						payAccNoHtml: payAccNoHtml
	    	        });
				}
				
				//设置我司付款账户 
				var payAccNm = $("#payAccNm").val();
				if(payAccNm != "") {
					manager.updateRow(rowdata,{
						payAccNm: payAccNm
	    	        });
				}
				
            },
            onUnSelectRow  : function (rowdata, rowid, rowobj)
            {
                var manager = $("#cost1").ligerGetGridManager();
    	        manager.updateRow(rowdata,{
    	        	actualAmt: 0,
    	        	floatAmt: 0,
    	        	feeRem: '',
    	        	rcvpymtAccNoHtml:'',
    	        	payAccNm: '',
    	        	payAccNoHtml: ''
    	        });
            },
            onAfterShowData: f_onAfterShowData,
            width: '100%',height:350,checkbox:true,usePager:false
        });
    }
    
    //机构收款账户初始化
    function initRecvList(){
  	   var instid = $("#fundrasinsid").val();
  	   $("#recvAcc").ligerComboBox({
            columns: [
	                { header: '开户行号', name: 'banAccNum', width: 140}, 
	                { header: '开户行名', name: 'banAccNm', width: 140}, 
	                { header: '账户名称', name: 'accNm', width: 120},
	                { header: '账号', name: 'accNum', width: 120},
		            { header: '账户ID', name: 'id'},
	               ],
	            url:'<%=path%>/rfbase/fncprjpaysch/initRecvList.do?insId='+instid,
	            ajaxType :'GET',
	            width: 200, slide: false,
	            selectBoxWidth: 680, selectBoxHeight: 240,
	            valueField:'id',textField: 'accNum',
	            initValue: '${raccid}'
	       });
     }
    function initPayList(){
  	   var instid = $("#fundrasinsid").val();
  	   $("#payAcc").ligerComboBox({
            columns: [
		            { header: '账户类型', name: 'accTypNm', width: 140}, 
	                { header: '开户行号', name: 'bkId', width: 140}, 
	                { header: '开户行名', name: 'bkNm', width: 140}, 
	                { header: '账户名称', name: 'accNm', width: 120},
	                { header: '账号', name: 'accNo', width: 120},
		            { header: '账户ID', name: 'id'},
	               ],
	            url:'<%=path%>/rfbase/fncprjpaysch/initPayList.do?insId='+instid,
	            ajaxType :'GET',
	            width: 200, slide: false,
	            selectBoxWidth: 680, selectBoxHeight: 240,
	            valueField:'id',textField: 'accNo'
	       });
    }
    //选择我司账户
 	function queryMy(){
 		
         $.ligerDialog.open({  title: '我司账户',height: 500,width: 850, url: '<%=path%>/system/sysBkAccInfo/toChooseListPage2.do?flag=dk'});
 	}
 	//选择我司账户设置数据
 	function setAccInfo(accNo,accNm,bkNm,bkNo,id){
 		$("#payAccNo").val(accNo);
 		$("#payAcc").val(id);
 		$("#payAccNm").val(accNm);
 	}
    //表格列待编辑事件，只允许编辑金额为0且选中的记录
    function f_onBeforeEdit(e)
    { 
        var manager = $("#cost1").ligerGetGridManager();
		var rowdata = manager.getRow(e.rowindex);
		var aramt = rowdata.arAmt;
		if(aramt == 0){
        	alert('该期次还款已结清，无需修改!');
			return false;
		}

        if (e.column.name == "actualAmt" || e.column.name == "floatAmt" || e.column.name == "feeRem")
        {
			if(manager.isSelected(e.rowindex)){
				return true;
			}else{
				alert('请选中该记录后，再编辑!'); 
				return false;
			}
        }
        return true;
    }
    //限制录入金额范围
    function f_onBeforeSubmitEdit(e)
    { 
            if (e.column.name == "actualAmt")
            {
                var manager = $("#cost1").ligerGetGridManager();
        		var rowdata = manager.getRow(e.rowindex);
        		var aramt = accAdd(rowdata.feeAmt-rowdata.paidUpAmt,rowdata.floatAmt);
        		if(manager.isSelected(e.rowindex) && (e.value == null || e.value =="")){
                	alert('选中记录应还金额不能为空!');
        			return false;
    			}
        		if(aramt<e.value){
                	alert('还款金额不能大于剩余未还（应还+当前浮动-已还）!');
        			return false;
        		}else{
        			return true;
        		}
            }
            if (e.column.name == "floatAmt")
            {
                var manager = $("#cost1").ligerGetGridManager();
        		var rowdata = manager.getRow(e.rowindex);
        		var f1 = Number(rowdata.arAmt)+Number(e.value);
        		if(f1<0){
        			alert('浮动金额不能超出负剩余未还款额!');
        			return false;
        		}else{
        			//调整浮动后，刷新本次还款为剩余应还公式计算结果
            		var aramt = Number(rowdata.feeAmt-rowdata.paidUpAmt+e.value);
    	      		manager.updateRow(rowdata,{
    	    	        	actualAmt: aramt.toFixed(2)
    	    	        });
        			return true;
        		}
            }
            return true;
    }
    //表格列待编辑事件，只允许编辑金额为0且选中的记录
    function f_onBeforeEdit0(e)
    { 
        var manager = $("#cost0").ligerGetGridManager();
		var rowdata = manager.getRow(e.rowindex);
		var aramt = rowdata.AR_AMT;
		if(aramt == 0){
        	alert('该期次还款已结清，无需修改!');
			return false;
		}

        if (e.column.name == "ACTUAL_AMT" || e.column.name == "FLOAT_AMT" || e.column.name == "FEE_REM")
        {
			if(manager.isSelected(e.rowindex)){
				return true;
			}else{
				alert('请选中该记录后，再编辑!'); 
				return false;
			}
        }
        return true;
    }
    //限制录入金额
    function f_onBeforeSubmitEdit0(e)
    { 
        if (e.column.name == "ACTUAL_AMT")
        {
            var manager = $("#cost0").ligerGetGridManager();
    		var rowdata = manager.getRow(e.rowindex);
    		var aramt = rowdata.FEE_AMT-rowdata.PAID_UP_AMT+rowdata.FLOAT_AMT;
    		if(manager.isSelected(e.rowindex) && (e.value == null || e.value =="")){
            	alert('选中记录应还金额不能为空!');
    			return false;
			}
    		if(aramt<e.value){
            	alert('还款金额不能大于剩余未还（应还+当前浮动-已还）!');
    			return false;
    		}else{
    			return true;
    		}
        }
        if (e.column.name == "FLOAT_AMT")
        {
            var manager = $("#cost0").ligerGetGridManager();
    		var rowdata = manager.getRow(e.rowindex);
    		var f1 = Number(rowdata.AR_AMT)+Number(e.value);
    		if(f1<0){
    			alert('浮动金额不能超出负剩余未还款额!');
    			return false;
    		}else{
    			//调整浮动后，刷新本次还款为剩余应还公式计算结果
        		var aramt = Number(rowdata.FEE_AMT-rowdata.PAID_UP_AMT+e.value);
	      		manager.updateRow(rowdata,{
	      				ACTUAL_AMT: aramt.toFixed(2)
	    	        });
    			return true;
    		}
        }
        return true;
    }

    //加载默认选中行
    function f_onAfterShowData(currentData){
    	var sumFeeAmt = 0;
    	if(currentData!=null){
	    	var arr = eval(currentData);      
	        var rows = arr.Rows;
            var manager = $("#cost1").ligerGetGridManager();
	        for(var i=0;i<rows.length;i++){
	        	if(rows[i].actualAmt!=null && rows[i].actualAmt != 0){
            		manager.select(i);
	        	}
	        	console.log(i+"_before:"+sumFeeAmt);
	        	if(rows[i].feeClsCd == 1){
		        	console.log(i+"_feeAmt:"+rows[i].feeAmt);
	        		sumFeeAmt = accAdd(sumFeeAmt , rows[i].feeAmt);
	        	}
	        	console.log(i+"_after:"+sumFeeAmt);
	        }
	        $("#sumFeeAmt").val(sumFeeAmt);
    	}
    }

    //加载默认选中行
    function f_onAfterShowData0(currentData){
    	if(currentData!=null){
	    	var arr = eval(currentData);      
	        var rows = arr.Rows;
            var manager = $("#cost0").ligerGetGridManager();
	        for(var i=0;i<rows.length;i++){
	        	if(rows[i].ACTUAL_AMT!=null && rows[i].ACTUAL_AMT != 0){
            		manager.select(i);
	        	}
	        }
    	}
    }
    //保存事件
    function saveFncPrjPayEvent(){
    	$("#repay_list_add_btn_id").click(function(event) {
    		startFlow();
    		//test();
        });
/*     	$("#repay_list_rtn_btn_id").click(function(event) {
    		cancelBtn()
        }); */
    }
	function cancelBtn(){
		 var TAB=top.mainApp.parentTab;
         var currentTabid=TAB.getSelectedTabItemID();
		 top.tab.removeTabItem(currentTabid);		
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	} 
	function test(){
        var manager1 = $("#cost1").ligerGetGridManager();
        var rows1 = manager1.getSelectedRows();
        var arr1 = eval(rows1);
        console.log(arr1);
        
        var allData = manager1.getData();
        var allArr = eval(allData);
        console.log(allArr);
        var sumFeeAmt = 0;
        var actTolAmt = $("#famt").val();
        var actTolAmt2 = 490100000;
        for(var i=0;i<allArr.length;i++){
        	sumFeeAmt = sumFeeAmt + allArr[i].feeAmt;
        }
        console.log(sumFeeAmt+"__"+actTolAmt);
        if(Number(sumFeeAmt) == Number(actTolAmt2)){
        	alert("ok");
        }else{
        	alert("Error");
        }
        
	}
	//加法函数，用来得到精确的加法结果
	//说明：javascript的加法结果会有误差，在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
	//调用：accAdd(arg1,arg2)
	//返回值：arg1加上arg2的精确结果
	function accAdd(arg1,arg2){
	 var r1,r2,rr,m,maxlen,result;
	 try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
	 try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}	 
	 console.log("length:"+r1+"_"+r2);
	 maxlen = Math.max(r1,r2);
	 m=Math.pow(10,maxlen);
	 console.log("Math.pow:"+m);
	 result = (arg1*m+arg2*m)/m;
	 console.log("result:"+result);
	 return result.toFixed(maxlen);
	}
	//发起审核流程
	function startFlow(){
 		if($("#repaystcd").val()==2){
			alert("项目还款处理中，不能重复发起流程！");
			return;
		}
		if($("#total0").val()==0){
			alert("该项目还款已全部结清，无需发起流程！");
			$("#repay_list_add_btn_id").val("返回");
			return;
		} 
		
 		if($("#repytp").val() == 1){
	 		if($("#recvAcc").val()=='' || $("#payAcc").val()==''){
				alert("请维护收付款账户！");
				return;
			} 			
 		}else{
	 		if($("#payAcc").val()==''){
				alert("请维护付款账户！");
				return;
			} 
 		}
        var manager1 = $("#cost1").ligerGetGridManager();
        var rows1 = manager1.getSelectedRows();
        var arr1 = eval(rows1);

        var manager0 = $("#cost0").ligerGetGridManager();
        var rows0 = manager0.getSelectedRows();
        var arr0 = eval(rows0);
        if(arr1.length==0 && arr0.length==0){
        	alert("请选择至少一条还款记录!");
        	return;
        }
        for(var i=0;i<arr1.length;i++){
        	var fldata = arr1[i].floatAmt;
        	var rmrk = arr1[i].feeRem;
        	if(fldata != null && fldata != 0 && rmrk == null){
        		alert("还款明细存在浮动，需填写备注说明情况");
        		return;
        	}
         	if(Number(arr1[i].actualAmt)>(accAdd(accAdd(Number(arr1[i].feeAmt),Number(arr1[i].floatAmt)),-Number(arr1[i].paidUpAmt)))){
        		alert("本次还款金额不能大于剩余未还（应还+当前浮动-已还）！");
        		return;
        	}
        }
        for(var i=0;i<arr0.length;i++){
        	var fldata = arr0[i].FLOAT_AMT;
        	var rmrk = arr0[i].FEE_REM;
        	if(fldata != null && fldata != 0  && rmrk == null){
        		alert("融资端明细存在浮动，需填写备注说明情况");
        		return;
        	}
        }
        var data = $("form").serializeArray();
    	var schid = $("#payschid").val();
		if(!schid)return;
		var modelTyp = 'R006';
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
				var jsondata = '{payschid:'+schid+',griddata0:'+JSON.stringify(arr0)+',griddata1:'+JSON.stringify(arr1)+
					',formdata:'+JSON.stringify(data)+'}';
				console.log(jsondata);
            	$.ajax({
              	   type: "POST",
             	   dataType:"json",
	           	   data:{
	        			id:schid,
	        			procDefKey:json.procDefKey,
	        			procDefId:json.procDefId,
	        			procNo:json.procNo,
	        			jsondata:jsondata
	        	   },
             	   url: "<%=path%>/rfbase/fncprjpaysch/addFlowStart.do",
	           		success:function(msg){
	        			wait_dialog.close();
	        			 if(msg.success == 1){
	      					 alert("保存成功!");
	      					griddata1.reload();
	      					griddata0.reload();
	      		    		 cancelBtn();
	           			 }else{
	          				UIUtils.alertErrorHold1(msg.info);
	           			 }
	        		}
             	});
            }
        }); 
	}
	</script>
</body>
</html>